package com.example.com.hupu.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.example.com.hupu.fragment.LiveFragment;
import com.example.com.hupu.fragment.NBAFragment;
import com.example.com.hupu.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目主界面
 */
public class MainActivity extends AppCompatActivity {

    @BindView(R.id.fl_container)
    FrameLayout flContainer;
    @BindView(R.id.tv_nba)
    TextView tvNba;
    @BindView(R.id.tv_live)
    TextView tvLive;
    private NBAFragment mNbaFragment;
    private LiveFragment mLiveFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        mNbaFragment = new NBAFragment();
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fl_container, mNbaFragment)
                .commit();
    }

    @OnClick({R.id.tv_nba, R.id.tv_live})
    public void onClick(View view) {
        Fragment clickFragment = null;
        switch (view.getId()) {
            case R.id.tv_nba:
                mNbaFragment = new NBAFragment();
                clickFragment = mNbaFragment;
                break;
            case R.id.tv_live:
                if(mLiveFragment == null){
                    mLiveFragment = new LiveFragment();
                    clickFragment = mLiveFragment;
                }
                break;
        }
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fl_container, clickFragment)
                .commit();
    }
}
